package com.cn.ccp.action.course;

import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;

import org.apache.log4j.Logger;

import com.cn.ccp.action.BaseAction;
import com.cn.ccp.bean.CourseNoticeBean;

/**
 * 课程公告action
 * @author renyongcheng
 *
 */
public class CourseNoticeAction extends BaseAction{
	private Logger log = Logger.getLogger(CourseNoticeAction.class);
	private String courseId,courseName,courseNotice,noteId;//课程id
	private List<CourseNoticeBean> noticeList;//公告列表
	private List<CourseNoticeBean> studentNoticeList;//学生选课公告列表
	public CourseNoticeAction(){
		Map<String, String> varMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		if(varMap.get("id") != null)
			courseId = varMap.get("id");
		courseName = getCourseService().getBeanById(courseId).getCourse_name();
		log.info("----------courseId = "+courseId);
		noticeList = getCourseService().getNoticeByCourseId(courseId);
	}
	
	/**
	 * 保存公告
	 * @return
	 */
	public void commint(){
		courseNotice = courseNotice.trim();
		if(courseNotice == null  || courseNotice.equals("")){
			showMsg("contentid", "course_page_course_notice_contents_is_null");
		}else{
			log.info("----------------------noteId  = "+noteId);
			log.info("----------------------courseId  = "+courseId);
			if(noteId != null && !"".equalsIgnoreCase(noteId.trim()))
				getCourseService().updateCourseNotice(noteId, courseNotice);
			else	
				getCourseService().saveCourseNotice(courseId, courseNotice);
		}
		
		noticeList = getCourseService().getNoticeByCourseId(courseId);
		courseNotice = "";
		noteId = null;
	}
	
	public void delNote(){
		Map<String, String> varMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		noteId = varMap.get("noteId");
		log.info("----------------------noteId  = "+noteId);
		if(noteId != null && !"".equalsIgnoreCase(noteId.trim()))
			getCourseService().delNote(noteId);
		noticeList = getCourseService().getNoticeByCourseId(courseId);
		noteId = null;
	}
	
	/**
	 * 选择编辑的公告
	 */
	public void selectEditNote(){
		Map<String, String> varMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		noteId = varMap.get("noteId");
		log.info("----------------------noteId  = "+noteId);
		if(noteId != null && !"".equalsIgnoreCase(noteId.trim())){
			CourseNoticeBean b = getCourseService().getNoticeById(noteId);
			courseNotice = b.getNotice();
		}
	}
	
	
	
	public String back(){
		return MAIN;
	}


	public String getCourseId() {
		return courseId;
	}


	public void setCourseId(String courseId) {
		this.courseId = courseId;
	}


	public String getCourseName() {
		return courseName;
	}


	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}


	public String getCourseNotice() {
		return courseNotice;
	}


	public void setCourseNotice(String courseNotice) {
		this.courseNotice = courseNotice;
	}

	public List<CourseNoticeBean> getNoticeList() {
		return noticeList;
	}

	public void setNoticeList(List<CourseNoticeBean> noticeList) {
		this.noticeList = noticeList;
	}

	public List<CourseNoticeBean> getStudentNoticeList() {
		return  getCourseService().getStudentNotice();
	}

	public String getNoteId() {
		return noteId;
	}

	public void setNoteId(String noteId) {
		this.noteId = noteId;
	}

	public void setStudentNoticeList(List<CourseNoticeBean> studentNoticeList) {
		this.studentNoticeList = studentNoticeList;
	}

	
}
